﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using StudyCompanion.Commons.Result;
using StudyCompanion.Core.API;
using StudyCompanion.Core.Models;
using StudyCompanion.Core.Share;
using StudyCompanion.Dto.Order;
using StudyCompanion.IServices;
using StudyCompanion.Model.Order;

namespace StudyCompanion.WebApi.Controllers;

/// <summary>
///     订单服务
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class OrderController : ApiController
{
    private readonly IOrderService _orderService;
    private readonly IUserContext _userContext;

    /// <summary>
    ///     订单服务
    /// </summary>
    /// <param name="userContext"></param>
    /// <param name="orderService"></param>
    public OrderController(IUserContext userContext
        , IOrderService orderService)
    {
        _userContext = userContext;
        _orderService = orderService;
    }

    /// <summary>
    ///     添加订单并支付
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("AddOrder")]
    public async Task<CommonResult<AddOrderVo>> AddOrderAndPay(OrderAddDto input)
    {
        return await _orderService.AddOrderAndPay(input, _userContext.Id);
    }

    /// <summary>
    ///     支付检查
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("PayCheck")]
    public async Task<CommonResult<int>> GetOrderTradeState(SimpleDto<long> input)
    {
        return await _orderService.GetOrderTradeState(input.Value, _userContext.Id);
    }
}